home *** CD-ROM | disk | FTP | other *** search
- /* NAME:
- MenuSelect.c
-
- WRITTEN BY:
- Dair Grant
-
- DESCRIPTION:
- This file contains a code resource to be installed as a Trap Patch.
-
- NOTES:
- We are applied as a patch to MenuSelect, and cause the Mac to play
- a sound when About... is selected from the Apple menu.
-
- ___________________________________________________________________________
- */
- //=============================================================================
- // Include files
- //-----------------------------------------------------------------------------
- #include <Gestalt.h>
- #include <ToolUtils.h>
- #include "A4Stuff.h"
- #include "SetupA4.h"
- #include "BT Constants.h"
- #include "BT AddrsTable.h"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // Private defines
- //-----------------------------------------------------------------------------
- #define AppleSymbol 0xF0 // The Apple symbol
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // Types
- //-----------------------------------------------------------------------------
- typedef pascal long (*MenuSelectProcPtr)(Point thePoint);
- typedef pascal void (*PlaySoundProcPtr)(void);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // Global Variables
- //-----------------------------------------------------------------------------
- MenuSelectProcPtr gPrevMenuSelect;
- PlaySoundProcPtr gPlaySound;
- Boolean gAlreadyRan = false;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // Private function prototypes
- //-----------------------------------------------------------------------------
- pascal long main(Point thePoint);
- short IsAppleMenu(MenuHandle theMenu);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // main : Entry point to our code resource.
- //-----------------------------------------------------------------------------
- // Note : We call the original MenuSelect, and then play a sound if the
- // item chosen was About... in the Apple menu.
- //-----------------------------------------------------------------------------
- pascal long main(Point thePoint)
- { long oldA4, retVal;
- MenuHandle theMenu;
- short theMenuID;
- BTAddressTable *theAddressTable;
-
-
-
-
- // Set up A4
- #ifndef powerc
- oldA4 = SetCurrentA4();
- #endif
-
-
-
- // If we've not already been called, do our one time initialisation stuff
- if (!gAlreadyRan)
- {
- Gestalt(kBellTestAddressTable, (long *) &theAddressTable);
- gPrevMenuSelect = (MenuSelectProcPtr) ((long) theAddressTable->theTable[kMenuSelect]);
- gPlaySound = (PlaySoundProcPtr) ((long) theAddressTable->theTable[kPlaySound]);
- gAlreadyRan = true;
- }
-
-
-
- // Call the original MenuSelect()
- retVal = gPrevMenuSelect(thePoint);
-
-
-
- // If the user selected something, check for the Apple menu
- theMenuID = HiWord(retVal);
- if (theMenuID)
- {
- // If it's the Apple menu, and the first item on it,
- // call our play-the-sound routine
- theMenu = GetMHandle(theMenuID);
- if (IsAppleMenu(theMenu) && (LoWord(retVal) == 1))
- gPlaySound();
- }
-
-
-
- // Restore A4 and return
- #ifndef powerc
- SetA4(oldA4);
- #endif
- return(retVal);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // IsAppleMenu : Is a given menu the Apple menu?
- //-----------------------------------------------------------------------------
- short IsAppleMenu(MenuHandle theMenu)
- {
-
-
- // If we don't have a menu, it can't be the Apple menu
- if (!theMenu)
- return(false);
-
-
- // If the menus name is one character long, and that character
- // is an Apple, it's the Apple menu
- if (((*theMenu)->menuData[0] == 1) &&
- (((*theMenu)->menuData[1] == 0x14) || ((*theMenu)->menuData[1] == AppleSymbol)))
- return(true);
- else
- return(false);
- }
-